import Vue from 'vue'
import router from './router'
import ElementUI from 'element-ui'
import '../src/assets/element-variables.scss'
import '../public/font-awesome-4.7.0/css/font-awesome.min.css'
import App from './App.vue'
import Axios from './axios'
import store from './store'
import global from './global'
import utils from './utils'
import filters from './filters'
import components from '@/components'
import VCharts from 'v-charts'
import 'babel-polyfill'
import 'es6-promise/auto'
import Export2Excel from '../src/excel/Export2Excel.js'
Vue.use(Export2Excel)

Vue.prototype.$Export2Excel = Export2Excel


const Moment = require('moment')

Vue.config.productionTip = false

// 注册element-ui
Vue.use(ElementUI)
// 注册v-chart
Vue.use(VCharts)

// axios组件
Vue.prototype.$axios = Axios
// 全局变量
Vue.prototype.$global = global
// Moment组件
Vue.prototype.$moment = Moment

// 注册common组件
Object.keys(components).forEach(componentName => {
  Vue.component(componentName, components[componentName])
})

// 注册工具类
Object.keys(utils).forEach(funcName => {
  Vue.prototype[funcName] = utils[funcName]
})

// 注册过滤类
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
// 使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
  const user = localStorage.getItem('userName')
  if (!user && to.path !== '/login') {
    next('/login')
  } else {
    next()
  }
})

new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')
